"""This script plots the LFP of a single trace and can also plot the raster plots of a the times mat file for a specific trace exported from Quiroga"""

import numpy
import scipy
import pylab
from scipy import fftpack
import scipy.io
def extract_data(filename):
    infile = open(filename, 'r')
    voltage = [] 
    times = []
    for line in infile:
        words = line.split() #this breaks each line into words
        volt = float(words[0])
        time = float(words[3])
        times.append(time)
        voltage.append(volt)
    infile.close()
    return voltage, times

voltage, times = extract_data('/home/davidmorton/Desktop/Data/043010RadialBar/273-Turtle_NI_Cortex_II-data') 

### Design an IIR Filter ###



#pylab.subplot(211)
#pylab.plot(times,voltage, 'k-')

v = numpy.array(voltage)
t = numpy.array(times)

Y = scipy.fftpack.fft(v)
bp = Y
for i in range(len(bp)):
    if i > 50: bp[i]=0
ibp = scipy.fftpack.ifft(bp)
pylab.subplot(111)
pylab.plot(t,ibp,'k-')
pylab.suptitle('LFP Radially Moving Bar 043010-273')
pylab.xlabel('Time (ms)')
pylab.show()

X = scipy.io.loadmat('/home/davidmorton/Desktop/Data/043010RadialBar/times_273-Turtle_NI_Cortex_II-data.mat')

cluster_times = numpy.array(X['cluster_class'])
spike_times = cluster_times[0:, 1]
pylab.vlines(spike_times,0.02,.03, colors='0.3')
